﻿using System.Collections.Generic;
using System.Linq;
using Hasiu.Entity;
using NHibernate;
using NHibernate.Linq;

namespace Hasiu.Service
{
    public class ProductTypeService
    {
        public static readonly ProductTypeService _ = new ProductTypeService();

        private ISession Session { get; set; }

        public ProductTypeService()
        {
            Session = NHibernateHelper.GetCurrentSession();
        }

        public void Save(ProductType productType)
        {
            Session.Clear();
            Session.Save(productType);
            Session.Flush();
        }

        public void Update(ProductType productType)
        {
            Session.Clear();
            Session.Update(productType);
            Session.Flush();
        }

        public void Delete(params string[] id)
        {
            Session.Clear();
            var query = Session.Query<ProductType>().Where(o => id.Contains(o.Id));
            foreach (var v in query)
            {
                Session.Delete(v);
            }
            Session.Flush();
        }

        public ProductType Get(string id)
        {
            return Session.Get<ProductType>(id);
        }

        public IList<ProductType> GetList()
        {
            return Session.Query<ProductType>().ToList();
        }
    }
}
